<?php

namespace App\Providers;

use App\Admin\Adver;
use App\Admin\Arole;
use Illuminate\Support\ServiceProvider;
use DB;
class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        view()->composer(
            '*', 'App\Http\Middlewal'
        );
        //主模板中的友情链接
        view()->composer('*',function($view)
        {
            $links=DB::table('links')->get()->toArray();
            $view->with('links',$links);
        });
        //主模板中的单品分类
        view()->composer('*',function($view)
        {
            $cate=DB::table('category')->get()->toArray();
            $view->with('cate',$cate);
        });
//主模板中的消息提醒
        view()->composer('*',function($view)
        {
            $user_id=Session()->get('user_id');
            $num=DB::table('sends')->where('user_id',$user_id)->where('status',1)->select(DB::Raw("count(*)as num"))->get()->toArray();
            $num=$num[0];
            $news=DB::table('sends')->where('user_id',$user_id)->where('status',1)->get()->toArray();
            $view->with(['news'=>$news,'num'=>$num]);
        });
        //广告
        view()->composer('*', function ($view) {
            $adver = Adver::select()->get();
            $view->with('adver',$adver);
        });
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
